/**
 * List of [tblName] [tblTitle] .
 * Created by buzhizhe CodeConvert on 2020/3/6 11:58:29.
 */

$(function () {
    initPage();
    loadData();
});

//初始化页面元素
function initPage() {
    VM = new Vue({
        delimiters: ["[[", "]]"],
        el: '#app',
        data: {
            formdata: {
            },
            result: {}
        }
    });

}

//加载数据
function loadData() {
    var id = GetQueryString("id");
    var url = ApiHost + "/{subFolder}/[tblName]view";
    $.ajax({
        type: "post",
        url: url,
        data: {
            id: id
        },
        dataType: "json",
        error: function (request) {
            ajaxError(request, $(this));
        },
        success: function (result) {
            ajaxSuccess(result, $(this));
            var code = result.statecode;
            if (code == 0) {
                VM.formdata = result.data;
                dealData();
            } else {
                layerAlert("获取失败：" + result.message);
            }
        }
    }
    );

}

//处理数据
function dealData() {
    //console.log("model data:",VM.formData);
}

//保存数据
function formSubmit() {
    
    var url = ApiHost + "/{subFolder}/[tblName]edit";
    var formData = $('#formedit').serialize();
    $.ajax({
        type: "post",
        url: url,
        data: formData,
        dataType: "json",
        error: function (request) {
            ajaxError(request, $(this));
        },
        success: function (result) {
            ajaxSuccess(result, $(this));
            var code = result.statecode;
            if (code == 0) {
                layerAlert("提交成功");
            } else if (code == 1001) {
                layerMsg("验证失败：" + result.message);
            } else {
                layerAlert("提交失败：" + result.message);
            }
        }
    }
    );

}



